/**
 * Created by lifan on 2015/11/15.
 */
var fs = require("fs");

/*//异步读取文件
 fs.readFile("../resources/readfile.js", 'utf-8', function(err, data){
 if(err){
 console.error(err);
 }else{
 console.log(data);
 }
 });*/

//同步读取文件
/*
var data = fs.readFileSync("resources/readfile.js", 'utf-8');
console.log(data);
console.log('===========read file end.==============');*/
fs.open('resources/readfile.js', 'r', function(err, fd){
    if (err) {
        console.log('read file error');
        return;
    } else {
        var buf = new Buffer(8);
        fs.read(fd, buf, 0, 8, null, function (err, bytesRead, buffer) {
            if(err){
                console.log(err);
                return;
            }
            console.log('bytesRead:'+bytesRead);
            console.log(buffer);
        });
    }
});